var MockAjaxBroker = Class.create();
MockAjaxBroker.prototype = Object.extend(new AjaxBroker(), {

		initialize : function(fileName, successListener, failureListener) {
			this.successListener = successListener;
			this.failureListener = failureListener;
			this.fileName = fileName;

			this.loadXMLDoc = function() {

				if (window.XMLHttpRequest) {
					this.ajaxRequest = new XMLHttpRequest();
				} else if (window.ActiveXObject) {
					alert("IE");
					this.ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
				if (this.ajaxRequest) {
					this.ajaxRequest.onreadystatechange = this.processReqChange.bind(this);
					this.ajaxRequest.open("GET", this.fileName, true);
					this.ajaxRequest.send(null);
				}

			};

			// handle onreadystatechange event of req object
		this.processReqChange = function() {
			// only if req shows "loaded"
			if (this.ajaxRequest == null) {
				alert("null");
				return null;
			}

			if (this.ajaxRequest.readyState == 4) {
				this.successListener(this.ajaxRequest.responseXML);
				this.ajaxRequest = null;
			}
		};

	},

	call : function() {
		try {

			this.loadXMLDoc();

		} catch (e) {
			Logger.debug(e);
		}
	}
});

var MockArtistRepository = Class.create();
MockArtistRepository.prototype = Object.extend(new ArtistRepository(), {
		initialize : function() {
		},
		list : function(artistName, limit, callback) {

			var fileName = "Resources/scripts/test/artist.search.xml";

			new MockAjaxBroker(fileName, function(xmlObject) {
				var artists = null;
				try {
					artists = new XMLParser().parseArtistSearch(xmlObject);
				} catch (e) {
					alert(e);
					Logger.error(e);
				}
				return callback(artists);
			}.bind(this), null).call();

		},
		info : function(artistName, mbid, callback) {

			var fileName = "Resources/scripts/test/artist.info.xml";

			new MockAjaxBroker(fileName, function(xmlObject) {
				var artist = new XMLParser().parseArtistInfo(xmlObject);
				return callback(artist);
			}.bind(this), null).call();

		}
});
